var e = require("../../../@babel/runtime/helpers/interopRequireDefault").default, a = require("../../../config/CT_share_index/index.js"), t = e(require("../../../behaviors/aucMiniAuth")), n = e(require("../../../behaviors/auth")), o = e(require("@vant/weapp/dialog/dialog.js")), i = e(require("../../../api/api_CTShare")), s = e(require("../../../utils/Tips")), r = e(require("../../../kta/index")), l = getApp(), u = l.eventBus;

Component({
    behaviors: [ t.default, n.default ],
    properties: {},
    data: {
        CTImageBaseUrl: a.imageBaseUrl.CT_share_index,
        shareId: "",
        listOrders: {},
        passTimeList: [],
        showDialogl: !1,
        phone: "",
        showBtns: !1
    },
    attached: function() {
        console.log("进入畅听王卡活动首页 attached，初始化全局参数"), l.globalData.loginCode = !1, l.globalData.hasAuth = !1, 
        l.globalData.aucMiniAuth.sid = "", this.getInviteOrder();
    },
    methods: {
        afterBindgetphonenumber: function(e, a) {
            var t = this;
            "0" === e.code ? (l.globalData.aucPhone = e.data.phone, this.setData({
                phone: l.globalData.aucPhone
            })) : s.default.toast("绑定手机号失败"), l.globalData.aucMiniAuth.sid = "", this.getInviteOrder().then(function() {
                if (a && a.currentTarget) switch (a.currentTarget.dataset.type) {
                  case "share1":
                    s.default.toast("您已绑定成功，请点击立即邀请按钮来分享活动哦~");
                    break;

                  case "share2":
                    t.gotoQrcode();
                    break;

                  default:
                    s.default.toast("您已绑定成功，请点击立即邀请按钮来分享活动哦~");
                } else s.default.toast("您已绑定成功，请点击立即邀请按钮来分享活动哦~");
            });
        },
        closeDialogl: function() {
            this.setData({
                showDialogl: !1
            });
        },
        showForbiddenToast: function() {
            this.data.listOrders.actionEndFlag && s.default.toast("活动已过期");
        },
        clickInv: function() {
            r.default.clickStat("d039428e373b4a60abb2e99f5c2e5b4b", {
                userphone: l.globalData.aucPhone
            });
        },
        gotoRule: function() {
            r.default.clickStat("cb9098a4897e43b6ab677b768acd5a33", {
                userphone: l.globalData.aucPhone
            }), u.emit("CT_share_rule", {
                listOrders: this.data.listOrders
            }), wx.navigateTo({
                url: "/pages/CT_share_rule/index?adtag=" + l.globalData.aucChannel
            });
        },
        showBindPopBox: function() {
            o.default.confirm({
                context: this,
                confirmButtonOpenType: "getPhoneNumber",
                bindGetphonenumber: "bindgetphonenumber",
                confirmButtonText: "绑定号码",
                cancelButtonText: "取消",
                richTextMessage: !0,
                richText: [ {
                    name: "div",
                    children: [ {
                        type: "text",
                        text: "未绑定手机号码，无法领取礼品"
                    } ]
                } ]
            });
        },
        getInviteOrder: function() {
            var e = this;
            return new Promise(function(a, t) {
                wx.showLoading({
                    title: "加载中"
                });
                var n = e;
                i.default.getInviteOrder().then(function(a) {
                    console.log("获取邀请列表接口返回res", a);
                    var t = a.code, n = a.result, i = a.msg;
                    "0" === t ? (e.setData({
                        listOrders: n
                    }), n.actionEndFlag && (l.globalData.actionEndFlag = n.actionEndFlag, wx.hideShareMenu())) : "40012" === t ? e.showBindPopBox() : o.default.alert({
                        context: e,
                        message: i || "获取邀请列表失败"
                    });
                }).then(function() {
                    wx.hideLoading(), n.setData({
                        showBtns: !0
                    }), console.log("aucMiniAuth", l.globalData.aucMiniAuth), console.log("绑定", l.globalData.aucPhone), 
                    l.globalData.aucPhone ? n.setData({
                        phone: l.globalData.aucPhone
                    }) : e.showBindPopBox(), a();
                }).catch(function() {
                    wx.hideLoading(), t();
                });
            });
        },
        tr: function(e) {
            switch (e) {
              case 0:
                return "已下单但";

              case 1:
                return "已激活但";

              case 2:
                return "已首充但";

              default:
                return "";
            }
        },
        clickExpireOrders: function() {
            var e = this;
            i.default.expireOrders().then(function(a) {
                console.log("过期订单列表接口返回 res", a);
                var t = a.code, n = a.result, o = a.msg;
                "0" === t ? (n.forEach(function(a) {
                    a.businessStatusText = e.tr(a.businessStatus), a.str = a.invitedSerialNumber + e.tr(a.businessStatus) + a.expireCnt + "个月会员权益已失效";
                }), e.setData({
                    showDialogl: !0,
                    passTimeList: n
                }), console.log("result", e.passTimeList)) : s.default.toast(o || "请求失败");
            }).catch(function() {
                s.default.toast("过期订单请求失败");
            });
        },
        gotoQrcode: function() {
            r.default.clickStat("8755edbe350048549fd46f528f35eb64", {
                userphone: l.globalData.aucPhone
            }), wx.navigateTo({
                url: "/pages/CT_share_qrcode/index?adtag=" + l.globalData.aucChannel
            });
        },
        gotoRecord: function() {
            r.default.clickStat("d59b222168fc44f989012e27c908bf70", {
                userphone: l.globalData.aucPhone
            }), u.emit("CT_share_inv", {
                listOrders: this.data.listOrders
            }), wx.navigateTo({
                url: "/pages/CT_share_inv/index?adtag=" + l.globalData.aucChannel
            });
        },
        gotoExchange: function() {
            r.default.clickStat("d7fca671fc224976ad4b519262a80de5", {
                userphone: l.globalData.aucPhone
            }), wx.navigateTo({
                url: "/pages/CT_share_exchange/index?adtag=" + l.globalData.aucChannel
            });
        }
    }
});